home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
ZICS.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-09
|
10KB
|
352 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: zics.cpp
// Title: 9 Digit ZIP Disc Interface
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
// This module contains code for the class ZI_CS.
//
// The code in this module may be written in C++ or C.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
//
//----------------------------------------------------------------------------
#include <zi.hpp>
#define USE_WIN_CS
#if OS_DOS
#include <zid.hpp>
#elif OS_WINDOWS
#include <ziw.hpp>
#else
#include <zio.hpp>
#endif
//----------------------------------------------------------------------------
// Description: Default constructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M ZI_CS::ZI_CS(Z4_STATE _state, PCSZ _pcszCity)
: ZN_WINDOW("WIN_CS", ZN_LOAD_CENTER|ZN_LOAD_HELPBAR|ZN_LOAD_NO_SHOW)
{
ZI_CS::Initialize(CL_INIT_CLASS);
state = _state;
pcszCity = _pcszCity;
Setup();
}
//----------------------------------------------------------------------------
// Description: Destructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M ZI_CS::~ZI_CS()
{
ZI_CS::Destroy(FALSE);
Terminate();
}
//----------------------------------------------------------------------------
// Description: This function attempts to make a partial match to a state
// name and place the virtual list selector on that state.
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
VOID FN_M ZI_CS::CheckMatch()
{
if (!fInit)
return ;
PCSZ pcszCity = GetString(FID(STR_SEARCH));
PCSZ pcszState = GetString(FID(STR_STATE));
if (pcszCity == NULL || pcszState == NULL)
return ;
CHAR szWork[160];
strcpy(szWork, pcszCity);
strtrim(szWork);
state = Z4_INQ::st_file.Find(pcszState);
if (stricmp(szLastMatch, szWork) == 0
&& stateLast == state)
return ;
strcpy(szLastMatch, szWork);
stateLast = state;
if (!Z4_INQ::cs_file.First(Z4_INQ::cs, stateLast, szLastMatch))
return ;
do
{
if (Z4_INQ::cs.state > state
|| (Z4_INQ::cs.state == state
&& stricmp(Z4_INQ::cs.szCity, szLastMatch) >= 0))
break;
}
while (Z4_INQ::cs_file.Next(Z4_INQ::cs));
SetVlistPos((LONG)Z4_INQ::cs_file.RecordNo());
return ;
}
//----------------------------------------------------------------------------
// Description: Destroy object. Free any resources used by object.
// Normally called by destructor.
// Should allow multiple calls from various classes.
// A class should almost always re-init its variables when
// it is destroyed to prevent accidents.
// Parameters: fDestroyAll Destroy parents also?
// Default is TRUE.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M ZI_CS::Destroy(BOOL fDestroyAll)
{
ZI_CS::Initialize(CL_INIT_CLASS_VARS);
if (fDestroyAll) // Destroy parent.
ZI_CS_PARENT::Destroy(fDestroyAll);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Display detail windows
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M ZI_CS::Detail()
{
if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, lCurrent))
return FALSE;
if (lClick != lCurrent)
SendMessage(ZiMainWindow(), ZI_MSG_CLICK);
lClick = lCurrent;
PZI_CS_DETAIL pzi_cs_detail = new ZI_CS_DETAIL(Z4_INQ::cs);
if (pzi_cs_detail == NULL)
return ErrorNoMem();
else if (pzi_cs_detail->IsValid())
pzi_cs_detail->Show();
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Initialize object.
// Normally called by constructor.
// Should allow multiple calls from various classes.
// Parameters: sInit Initialization code. May be one of the following:
// CL_INIT_CLASS Reset class variables and
// and dynamic allocations for
// this class only.
// CL_INIT_CLASS_VARS Reset class variables for
// this class only.
// CL_INIT_VARS Reset class variables for
// this class only.
// CL_INIT_ALL Initialize class and all
// parent class, including
// dynamic memory allocation.
// Default is CL_INIT_ALL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M ZI_CS::Initialize(SHORT sInit)
{
if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
ZI_CS_PARENT::Initialize(sInit);
szLastMatch[0] = '\0';
lCurrent = 0;
lRecords = 0;
stateLast = Z4_ST_INVALID;
state = Z4_ST_INVALID;
fInit = FALSE;
lClick = -1L;
pcszCity = NULL;
return TRUE;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M ZI_CS::Query(PZN_VLIST_ELEM pzn_vlist_elem)
{
pzn_vlist_elem->pszBuf = szFormat;
szFormat[0] = '\0';
if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, pzn_vlist_elem->lId))
return FALSE;
sprintf(szFormat, "\t%s\t%s\t%s\t%s%s",
Z4_ST_FILE::Abbreviation(Z4_INQ::cs.state), Z4_INQ::cs.szCity,
Z4_INQ::cs.szZip5Lo,
(Z4_INQ::cs.szZip5Hi[0] ? "- ": ""),
Z4_INQ::cs.szZip5Hi);
return TRUE;
}
//----------------------------------------------------------------------------
// Description:
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M ZI_CS::Select()
{
if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, lCurrent))
return FALSE;
PSZ pszZIP = NULL;
if (!Z4_INQ::cs.szZip5Hi[0])
{
if (lClick != lCurrent)
SendMessage(ZiMainWindow(), ZI_MSG_CLICK);
pszZIP = Z4_INQ::cs.szZip5Lo;
}
SendMessage(ZiMainWindow(), ZI_MSG_STATE, NULL, (PVOID)Z4_ST_FILE::Abbreviation(Z4_INQ::cs.state));
PCSZ pcszCity = (Z4_INQ::cs.facility == Z4_FACILITY_OTHER ? Z4_INQ::cs.szLastLineName: Z4_INQ::cs.szCity);
SendMessage(ZiMainWindow(), ZI_MSG_CITY, NULL, (PVOID)pcszCity);
SendMessage(ZiMainWindow(), ZI_MSG_ZIP5, NULL, (PVOID)pszZIP);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Event monitor function.
// Parameters: msg Event code
// pv1 Data pointer 1
// pv2 Data pointer 2
// Returns: Event code
//----------------------------------------------------------------------------
ZN_MSG FN_M ZI_CS::User(ZN_MSG msg, PVOID, PVOID pv2)
{
switch (msg)
{
case ZN_MSG_INIT:
{
SetMouse(MOUSE_HOURGLASS);
SetString(FID(STR_STATE), (PCSZ)Z4_ST_FILE::Abbreviation(state));
if (pcszCity)
SetString(FID(STR_SEARCH), pcszCity);
fInit = TRUE;
CheckMatch();
SetMouse();
SetCurrent(FID(STR_SEARCH));
}
return msg;
case ZN_MSG_TERMINATE:
return msg;
case ZN_MSG_VLIST_INIT:
{
static int aiTabstops[] = { 2, 6, 55, 62, 0, 0 };
PZN_VLIST_INIT pzn_vlist_init = (PZN_VLIST_INIT)pv2;
lRecords = (LONG)Z4_INQ::cs_file.Records();
pzn_vlist_init->lElems = lRecords;
pzn_vlist_init->fs = ZN_VLIST_SINGLE|ZN_VLIST_TITLE;
pzn_vlist_init->aiTabstops = aiTabstops;
}
return msg;
case ZN_MSG_VLIST_TITLE:
{
PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
pzn_vlist_elem->pszBuf = szFormat;
strcpy(szFormat, "\tST\tCity\tZIP");
}
return msg;
}
if (IsError()) // Error condition
return msg;
switch (msg)
{
case ZN_MSG_LIST_SELECT:
case ZN_MSG_LIST_DBL_CLK:
case ZN_MSG_STRING_CHANGE:
CheckMatch();
break;
case ZN_MSG_VLIST_QUERY:
Query((PZN_VLIST_ELEM)pv2);
break;
case ZN_MSG_VLIST_SELECT:
{
PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
lCurrent = pzn_vlist_elem->lId;
}
// Fall through
case ZN_MSG_VLIST_CURRENT:
{
PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
LONG lRec = pzn_vlist_elem->lId;
sprintf(szFormat, "City %ld of %ld", lRec+1, lRecords);
SetHelp(szFormat);
}
break;
case ZN_MSG_VLIST_DBL_CLK:
{
PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
lCurrent = pzn_vlist_elem->lId;
}
// Fall through
case TB_DETAIL:
Detail();
break;
case ZN_MSG_HELP:
return ZN_MSG_NO_HELP;
case TB_CLOSE:
Close();
break;
case TB_SELECT:
Select();
Close();
break;
case TB_HELP:
NotDone();
break;
}
return msg;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------